﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Input;

namespace chemicall
{

    public class EraseMenu : MenuScreen
    {
        GameManager gM;

        public EraseMenu()
            : base("Effacer quelle partie ?")
        {
            gM = GameManager.getInstance();
            string save1 = gM.LoadNameSave("../../../Sauvegarde1.txt");
            string save2 = gM.LoadNameSave("../../../Sauvegarde2.txt");

            MenuItem save1MenuEntry = new MenuItem(save1);
            MenuItem save2MenuEntry = new MenuItem(save2);
            MenuItem backMenuEntry = new MenuItem("Retour");

            save1MenuEntry.Selected += Save1MenuEntrySelected;            
            save2MenuEntry.Selected += Save2MenuEntrySelected;
            backMenuEntry.Selected += BackMenuEntrySelected;

            MenuEntries.Add(save1MenuEntry);
            MenuEntries.Add(save2MenuEntry);
            MenuEntries.Add(backMenuEntry);
        }

        void Save1MenuEntrySelected(object sender, System.EventArgs e)
        {
            gM.EraseGameManager("../../../Sauvegarde1.txt");
            gM.fichier = "../../../Sauvegarde1.txt";
            this.ScreenManager.LastScreen = this;
            ScreenManager.AddScreen(new ChooseName("../../../Sauvegarde1.txt"), PlayerIndex.One);
        }

        void Save2MenuEntrySelected(object sender, System.EventArgs e)
        {
            gM.EraseGameManager("../../../Sauvegarde2.txt");
            gM.fichier = "../../../Sauvegarde2.txt";
            this.ScreenManager.LastScreen = this;
            ScreenManager.AddScreen(new ChooseName("../../../Sauvegarde2.txt"), PlayerIndex.One);
        }

        void BackMenuEntrySelected(object sender, System.EventArgs e)
        {
            ScreenManager.AddScreen(this.ScreenManager.LastScreen, PlayerIndex.One);
            this.ScreenManager.LastScreen = this;
        }
    }
}
